// app/middleware/gzip.js
// const isJSON = require('koa-is-json');
// const zlib = require('zlib');

module.exports = (options, app) => {
    return async function mytoken(ctx, next) {
        const whiteList = ['/api/login', '/api/register']
        if (whiteList.includes(ctx.request.url)) {
            await next();
        } else {
            //解析token
            let token = ctx.request.header.authorization.split('Bearer ')[1]
            const username = app.jwt.verify(token, app.jwt.secret).username
            ctx.request.body.username = username;
            await next();
        }
    };
};